#include <iostream>

using namespace std;
using ll=long long;
const int N=1e7+10;

ll a[N];
ll b[N];
ll c[N];
ll n,m;
int main()
{
	cin>>n>>m;
	while(m--)
	{
		int l,r,s,e;
		scanf("%d%d%d%d",&l,&r,&s,&e);
		int d=(e-s)/(r-l);
		a[l]+=s;
		a[l+1]-=s;
		a[l+1]+=d;
		a[r+1]-=e;
		a[r+1]-=d;
		a[r+2]+=e;
	}
	ll yh=0;
	ll ret=0;
	for(int i=1;i<=n;i++)
	{
		b[i]=b[i-1]+a[i];
		c[i]=c[i-1]+b[i];
		yh^=c[i];
		ret=max(ret,c[i]);
	}
	cout<<yh<<' '<<ret<<endl;
	
	
	return 0;
}

// a a+d a+2d a+3d ... e-d e
// a d  d  d  .. d d -e
// a  a-d 0 0..  0 0 -e-d
